package com.lzx.spring3.aop.cglib;

import com.lzx.spring3.meta.User;
import com.lzx.spring3.meta.Watch;

import net.sf.cglib.beans.BeanCopier;

public class Utils {

	static BeanCopier beanCopier = BeanCopier.create(User.class, User.class,
			false);

	/**
	 * 
	 * @param from
	 * @param to
	 */
	public static void copy(Object from, Object to) {
		// BeanCopier创建的代价很大，做好把BeanCopier缓存起来
		BeanCopier beanCopier = BeanCopier.create(from.getClass(),
				to.getClass(), false);

		beanCopier.copy(from, to, null);

	}

	public static void main(String[] args) {
		User user = new User();
		user.setName("abc");
		user.setAge(25);
		User user2 = new User();
		System.out.println(user);
		System.out.println(user2);

		// copy(user, user2);
		// System.out.println(user);
		// System.out.println(user2);
		Watch.start();
		int count = 1;
		while (count > 0) {
			count--;
			//通过反射实现
			BeanUtils.copyProperties(user2, user2);
			//通过cglib实现
			copy(user, user2);

		}
		Watch.dis();

		System.out.println(user);
		System.out.println(user2);
		

	}

}
